package com.letv.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 影视大全静态切面方法
 */
public class DaquanAop {

    public static enum DaquanOfflineMark {TOTAL_WEBSITE, TOTAL_DETAIL, INCREASE;};

    /**
     * Logger, 不记录数据，打印大全服务正常日志信息。
     */
    private static final Logger LOGGER_DAQUAN = LoggerFactory.getLogger("daquan");

    /**
     * Logger, 全量站点源数据
     */
    private static final Logger LOGGER_DAQUAN_TOTAL_WEBSITE = LoggerFactory.getLogger("daquanTotalWebsite");

    /**
     * Logger, 全量详情数据
     */
    private static final Logger LOGGER_DAQUAN_TOTAL_DETAIL = LoggerFactory.getLogger("daquanTotalDetail");

    /**
     * 打印大全日志
     * @param keyList List<String>, keyList中所有key共用一个value
     * @param value String
     * @param daquanOfflineMark DaquanOfflineMark
     */
    public static void addToDaquanLog(List<String> keyList, String value, DaquanOfflineMark daquanOfflineMark) {
        if(null == keyList || keyList.size() == 0 || StringUtils.isBlank(value) || null == daquanOfflineMark) return;
        String dataJoinCharacter = " ";
        try {
            StringBuffer keyListStringBuffer = new StringBuffer("");
            for(String key : keyList) {
                if(StringUtils.isBlank(key)) continue;
                keyListStringBuffer.append(key).append(CommonUtil.COMMON_JOIN_CHARACTER);
            }
            if(keyListStringBuffer.length() == 0) return;
            StringBuffer data = new StringBuffer(keyListStringBuffer.deleteCharAt(keyListStringBuffer.length() - 1).toString())
                                                .append(dataJoinCharacter)
                                                .append(CommonUtil.compressZlibBase64(value));
            switch(daquanOfflineMark) {
            case TOTAL_WEBSITE:
                LOGGER_DAQUAN_TOTAL_WEBSITE.info(data.toString());
                break;
            case TOTAL_DETAIL:
                LOGGER_DAQUAN_TOTAL_DETAIL.info(data.toString());
                break;
            case INCREASE:
                break;
            default:
                break;
            }
        } catch(Exception e) {
            LOGGER_DAQUAN.error("method CommonUtil.addToDaquanLog catch error", e);
        }
    }

    public static void main(String[] args) {
        List<String> daquanKeyList = new ArrayList<String>();
        daquanKeyList.add("key1");
        daquanKeyList.add("key2");
        daquanKeyList.add("key3");
        DaquanAop.addToDaquanLog(daquanKeyList, "灵梦萌萌哒", DaquanOfflineMark.TOTAL_DETAIL);
    }
}
